home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / AmigaSystem / Scalos / PreferencesLib / examples / Blitz / multiple.bb2 < prev    next >
Text File  |  2002-10-28  |  3KB  |  74 lines

  1. ; Simple example of multiple data items within one tag
  2. ; You should have a look at the "single.bb2" example first
  3.  
  4. INCDIR "include:"
  5. XINCLUDE "scalos/preferences.bb2"
  6.  
  7. prefname$ = "Example"   ; Name to refer to PrefsHandle with
  8.  
  9.  
  10. ; First of all we need to allocate a PrefsHandle by name
  11. ; (There is no specific type for a PrefsHandle, as long as it is a long or a pointer)
  12. *prefhandle.l = AllocPrefsHandle_(&prefname$)
  13. If *prefhandle
  14.     NPrint "PrefsHandle successfully allocated"
  15.  
  16.     ; We need an ID and Tag value to refer to a specific preference with
  17.     ; so we create that here (or you could just use them in the library calls)
  18.     ; Remember that the ID must be a long created from 4 ASCII characters
  19.     ; and the Tag cannot be 0
  20.     ID.l = Cvl("MAIN")
  21.     Tag.l = 2
  22.  
  23.  
  24.     ; We keep track of the current entry number so that we can keep on adding
  25.     ; at the end of the list of data items. You can of course, pass any entry
  26.     ; number and it will be inserted in the correct place in the list, unless
  27.     ; the data item already exists and the size is the same then it will be overwritten
  28.     en.l = 0
  29.  
  30.  
  31.     ; Enter a loop which allows the user to enter some data to be stored in the
  32.     ; list.
  33.     Repeat
  34.         ; Prompt user and get a string from them
  35.         Print "Enter a name or leave blank to quit and press return: "
  36.         prefdata$ = Edit$(256)
  37.  
  38.         ; If the string is empty, we do not do anything with it, as that
  39.         ; is the condition for quitting the loop
  40.         If prefdata$<>""
  41.             ; Store string as a preference
  42.             SetEntry_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1, en
  43.  
  44.             ; increase entry number to store data at
  45.             en+1
  46.         End If
  47.     Until prefdata$=""
  48.  
  49.  
  50.     ; Now we will show each data item in turn, as well as removing it,
  51.     ; this means we do not need to play around with entry numbers here
  52.  
  53.     ; Create some memory for storing the retrieved data
  54.     Dim temp.b(256)
  55.  
  56.     ; While the amount of retrieved bytes is > 0 (this means that it was able
  57.     ; to retrieve some data, and thus the list is not empty)
  58.     While(GetEntry_(*prefhandle, ID, Tag, &temp(0), 256, 0))
  59.         ; Print the data retrieved and then remove that entry
  60.         NPrint "Retrieved: ",Peek$(&temp(0))
  61.         If RemEntry_(*prefhandle, ID, Tag, 0) Then NPrint "Entry removed" Else NPrint "Entry not removed"
  62.     Wend
  63.  
  64.     ; Finally we free the prefs handle
  65.     FreePrefsHandle_ *prefhandle
  66. End If
  67.  
  68. NPrint "Press LMB+RMB to quit"
  69. While Joyb(0)<>3
  70.     Delay_ 1
  71. Wend
  72. End
  73.  
  74.